Component({
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    current: {
      type: Object,
      value: {}
    },
    detail: {
      type: Object,
      value: {}
    }
  },
  data: {
    num: 1
  },
  methods: {
    onChange ({detail}) {
      this.setData({ num: detail })
    },
    close () {
      this.triggerEvent('close')
    },
    join () {
      this.triggerEvent('join', { materialId: this.data.detail.Material.id, specKey: this.data.current.specKey, num: this.data.num })
    },
    sample () {
      wx.$nav.navigateTo(`/pages/account/shopCart/confirm/index?form=now&specKey=${this.data.current.specKey}&materialId=${this.data.detail.Material.id}&num=${this.data.num}`)
    },
    beforeOpen () {
      let specKeys = this.data.current.specKey.split('_')
      this.data.detail.spec.map((item, index) => item.specItem.map((v, num) => {
        let rowIndex = specKeys.findIndex(row => parseInt(row) === v.id)
        if (rowIndex > -1) item.activeId = v.id
      }))
      this.setData({ 'detail.spec': this.data.detail.spec })
    },
  },
})